//
//  SFSafariViewControllerExtension.swift
//  DMRCommonBaseLib
//
//  Created by edy on 2025/10/27.
//

import Foundation
import UIKit
import SafariServices

public extension SFSafariViewController {
    
    static func present(at vc: UIViewController, urlStr: String, configHandler: ((_ sfvc: SFSafariViewController) -> Void)?) {
        guard let cUrlStr = urlStr.addingPercentEncoding(withAllowedCharacters: CharacterSet(charactersIn: "`%^{}\"[]|\\<> ").inverted) else { return
        }
        guard let url = URL(string: cUrlStr) else {
            return
        }
        
        let sf = SFSafariViewController(url: url)
        sf.view.backgroundColor = .white
        sf.preferredBarTintColor = UIColor.black
        sf.preferredControlTintColor = .white
        if let configHandler = configHandler {
            configHandler(sf)
        }
        
        vc.present(sf, animated: true) { }
    }
    
}
